﻿using Consul;
using Microsoft.Owin.Hosting;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace iS3.Server.Core
{
    public class StartWebApi
    {
        public static void Start()
        {
            string baseAddress = getAddress();
            string serverName = getServerName();
            try
            {
                using (WebApp.Start<Startup>(baseAddress))
                {
                    Console.WriteLine(string.Format("{0} : Server is opened at  {1}", serverName, baseAddress));
                    Console.WriteLine("程序已启动,按任意键退出");
                    Console.ReadLine();
                }

            }
            catch(Exception ex)
            {

            }
 
        }
        public static string getAddress()
        {
            string ip = ConsulManager.ipInner;
            string port = ConsulManager.port;
            string baseAddress = $"http://{ip}:{port}/";
            return baseAddress;
        }
        public static string getServerName()
        {
            return ConfigurationManager.AppSettings["ServerID"];
        }
    }
}
